package cn.dzhang.spring.boot.remoting.client;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
import org.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor;

import cn.dzhang.spring.boot.remoting.BasicAuthenticationHttpInvokerRequestExecutor;
import cn.dzhang.spring.boot.service.DeviceService;
import cn.dzhang.spring.boot.service.RoleService;
import cn.dzhang.spring.boot.service.UserService;

@Configuration
public class RemotingSetting {
	@Bean
	public HttpInvokerProxyFactoryBean userService() {
		HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
		proxy.setServiceInterface(UserService.class);
		proxy.setServiceUrl("http://localhost:8080/UserService");
		proxy.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor());
		return proxy;
	}
	
	@Bean
	public HttpInvokerProxyFactoryBean roleService() {
		HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
		proxy.setServiceInterface(RoleService.class);
		proxy.setServiceUrl("http://localhost:8080/RoleService");
		proxy.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor());
		return proxy;
	}
	@Bean
	public HttpInvokerProxyFactoryBean deviceService() {
		HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
		proxy.setServiceInterface(DeviceService.class);
		proxy.setServiceUrl("http://localhost:8080/DeviceService");
		proxy.setHttpInvokerRequestExecutor(httpInvokerRequestExecutor());
		return proxy;
	}

	@Bean
	public HttpInvokerRequestExecutor httpInvokerRequestExecutor() {
		BasicAuthenticationHttpInvokerRequestExecutor executor = new BasicAuthenticationHttpInvokerRequestExecutor();
		return executor;
	}
}
